package com.siwei.mes.entity.experiment.fineAggregate;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import com.siwei.mes.common.util.NullUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 细骨料-压碎值指标
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class FineAggregateYszzb {
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "5.00mm~2.50mm平均值")//1
    private String pjz0 = "";
    @ApiModelProperty(value = "2.50mm~1.25mm平均值")//1
    private String pjz1 = "";
    @ApiModelProperty(value = "1.25mm~630μm平均值")//1
    private String pjz2 = "";
    @ApiModelProperty(value = "630μm~315μm平均值")//1
    private String pjz3 = "";
    @ApiModelProperty(value = "暂定未用到")
    private String pjz4 = "";
    @ApiModelProperty(value = "暂定未用到")
    private String pjz5 = "";
    @ApiModelProperty(value = "暂定未用到")
    private String pjz6 = "";
    @ApiModelProperty(value = "暂定未用到")
    private String pjz7 = "";
    @ApiModelProperty(value = "总压碎指标")
    private String zyszb = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "压碎值指标信息")
    private List<FineAggregateYszzb.YszzbList> yszzbList = Collections.singletonList(new FineAggregateYszzb.YszzbList());


    @Data
    @Accessors(chain = true)
    @ApiModel("压碎值指标信息")
    public static class YszzbList {
        @ApiModelProperty(value = "第n次实验")
        private String typeName = "";
        @ApiModelProperty(value = "平均值")
        private String pjz = "";
        @ApiModelProperty(value = "详细信息")
        private List<FineAggregateYszzb.Datum> data = Collections.singletonList(new FineAggregateYszzb.Datum());

    }

    @Data
    @Accessors(chain = true)
    @ApiModel("详细信息")
    public static class Datum {
        @ApiModelProperty(value = "第一级（300μm~600μm）")
        private String target = "";
        @ApiModelProperty(value = "试样质量")
        private String syzl = "";
        @ApiModelProperty(value = "筛余量")
        private String syl = "";
        @ApiModelProperty(value = "通过量")
        private String tgl = "";
        @ApiModelProperty(value = "结果")
        private String jg = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        FineAggregateYszzb entity = new FineAggregateYszzb();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, FineAggregateYszzb.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, FineAggregateYszzb.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        FineAggregateYszzb entity = JsonUtils.getObject(objJson, FineAggregateYszzb.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz0()) || "null".equals(entity.getPjz0())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(FineAggregateYszzb entity, Map<String, Object> data) {
        List<FineAggregateYszzb.YszzbList> yszzbList = entity.getYszzbList();
        if (CollectionUtil.isNotEmpty(yszzbList)) {
            for (FineAggregateYszzb.YszzbList yszz : yszzbList) {
                if ("第一次实验".equals(yszz.getTypeName())) {
                    List<FineAggregateYszzb.Datum> dataList = yszz.getData();
                    for (FineAggregateYszzb.Datum datum : dataList) {
                        if ("5.00mm~2.50mm".equals(datum.getTarget())) {
                            if (data.get("S1") != null) {
                                datum.setSyzl(data.get("S1").toString());
                            }
                            if (data.get("S2") != null) {
                                datum.setSyl(data.get("S2").toString());
                            }
                            if (data.get("S3") != null) {
                                datum.setJg(data.get("S3").toString());
                            }
                        } else if ("2.50mm~1.25mm".equals(datum.getTarget())) {
                            if (data.get("S10") != null) {
                                datum.setSyzl(data.get("S10").toString());
                            }
                            if (data.get("S11") != null) {
                                datum.setSyl(data.get("S11").toString());
                            }
                            if (data.get("S12") != null) {
                                datum.setJg(data.get("S12").toString());
                            }
                        } else if ("1.25mm~630μm".equals(datum.getTarget())) {
                            if (data.get("S19") != null) {
                                datum.setSyzl(data.get("S19").toString());
                            }
                            if (data.get("S20") != null) {
                                datum.setSyl(data.get("S20").toString());
                            }
                            if (data.get("S21") != null) {
                                datum.setJg(data.get("S21").toString());
                            }
                        } else if ("630μm~315μm".equals(datum.getTarget())) {
                            if (data.get("S28") != null) {
                                datum.setSyzl(data.get("S28").toString());
                            }
                            if (data.get("S29") != null) {
                                datum.setSyl(data.get("S29").toString());
                            }
                            if (data.get("S30") != null) {
                                datum.setJg(data.get("S30").toString());
                            }
                        }
                    }
                } else if ("第二次实验".equals(yszz.getTypeName())) {
                    List<FineAggregateYszzb.Datum> dataList = yszz.getData();
                    for (FineAggregateYszzb.Datum datum : dataList) {
                        if ("5.00mm~2.50mm".equals(datum.getTarget())) {
                            if (data.get("S4") != null) {
                                datum.setSyzl(data.get("S4").toString());
                            }
                            if (data.get("S5") != null) {
                                datum.setSyl(data.get("S5").toString());
                            }
                            if (data.get("S6") != null) {
                                datum.setJg(data.get("S6").toString());
                            }
                        } else if ("2.50mm~1.25mm".equals(datum.getTarget())) {
                            if (data.get("S13") != null) {
                                datum.setSyzl(data.get("S13").toString());
                            }
                            if (data.get("S14") != null) {
                                datum.setSyl(data.get("S14").toString());
                            }
                            if (data.get("S15") != null) {
                                datum.setJg(data.get("S15").toString());
                            }
                        } else if ("1.25mm~630μm".equals(datum.getTarget())) {
                            if (data.get("S22") != null) {
                                datum.setSyzl(data.get("S22").toString());
                            }
                            if (data.get("S23") != null) {
                                datum.setSyl(data.get("S23").toString());
                            }
                            if (data.get("S24") != null) {
                                datum.setJg(data.get("S24").toString());
                            }
                        } else if ("630μm~315μm".equals(datum.getTarget())) {
                            if (data.get("S31") != null) {
                                datum.setSyzl(data.get("S31").toString());
                            }
                            if (data.get("S32") != null) {
                                datum.setSyl(data.get("S32").toString());
                            }
                            if (data.get("S33") != null) {
                                datum.setJg(data.get("S33").toString());
                            }
                        }
                    }
                } else if ("第三次实验".equals(yszz.getTypeName())) {
                    List<FineAggregateYszzb.Datum> dataList = yszz.getData();
                    for (FineAggregateYszzb.Datum datum : dataList) {
                        if ("5.00mm~2.50mm".equals(datum.getTarget())) {
                            if (data.get("S7") != null) {
                                datum.setSyzl(data.get("S7").toString());
                            }
                            if (data.get("S8") != null) {
                                datum.setSyl(data.get("S8").toString());
                            }
                            if (data.get("S9") != null) {
                                datum.setJg(data.get("S9").toString());
                            }
                        } else if ("2.50mm~1.25mm".equals(datum.getTarget())) {
                            if (data.get("S16") != null) {
                                datum.setSyzl(data.get("S16").toString());
                            }
                            if (data.get("S17") != null) {
                                datum.setSyl(data.get("S17").toString());
                            }
                            if (data.get("S18") != null) {
                                datum.setJg(data.get("S18").toString());
                            }
                        } else if ("1.25mm~630μm".equals(datum.getTarget())) {
                            if (data.get("S25") != null) {
                                datum.setSyzl(data.get("S25").toString());
                            }
                            if (data.get("S26") != null) {
                                datum.setSyl(data.get("S26").toString());
                            }
                            if (data.get("S27") != null) {
                                datum.setJg(data.get("S27").toString());
                            }
                        } else if ("630μm~315μm".equals(datum.getTarget())) {
                            if (data.get("S34") != null) {
                                datum.setSyzl(data.get("S34").toString());
                            }
                            if (data.get("S35") != null) {
                                datum.setSyl(data.get("S35").toString());
                            }
                            if (data.get("S36") != null) {
                                datum.setJg(data.get("S36").toString());
                            }
                        }
                    }
                }
            }
        }
        if (data.get("S37") != null) {
            entity.setPjz0(data.get("S37").toString());
        }
        if (data.get("S38") != null) {
            entity.setPjz1(data.get("S38").toString());
        }
        if (data.get("S39") != null) {
            entity.setPjz2(data.get("S39").toString());
        }
        if (data.get("S40") != null) {
            entity.setPjz3(data.get("S40").toString());
        }
        if (data.get("S41") != null) {
            entity.setZyszb(data.get("S41").toString());
        }
    }
}
